package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.Department;
import cn.wolfcode.ssm.mapper.DepartmentMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void deleteById(Long id) {
        if(id != null){
            departmentMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public void save(Department department) {
        departmentMapper.insert(department);

    }

    @Override
    public Department selectById(Long id) {
        if(id != null){
            return departmentMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Department> departments = departmentMapper.selectAll();
        return new PageInfo<>(departments);
    }

    @Override
    public List<Department> ListAll() {
        return departmentMapper.selectAll();
    }


    @Override
    public void updateById(Department department) {
        departmentMapper.updateByPrimaryKey(department);
    }
}
